//加载公共样式
require('../../assets/css/common.less')

import Swiper from '../../lib/swiper/swiper-bundle.min';
require('../../lib/swiper/swiper-bundle.min.css')
//加载自己的样式
require('./mine.less')
//引入tabbar渲染函数
const renderTabbar=require('../../utils/tabbar')
const request = require('../../utils/request')
window.onload=()=>{
    renderTabbar();
  

    // swiper部分
  let mySwiper = new Swiper('.swiper', {
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
    loop: true, // 循环模式选项
    autoplay: {
      delay: 2500,
      disableOnInteraction: false,
    },//自动翻页

    // 如果需要分页器
    pagination: {
      el: ".swiper-pagination",
    },

  })

 let avater=document.querySelector('#avater') 
 let days=document.querySelector('.days')
 let nowday=document.querySelector('.nowday')
 let minsp1=document.querySelector('.minsp1')
 let sumsp1=document.querySelector('.sumsp1')
 let userhead=document.querySelector('.userhead')
 const husername=document.querySelector('#husername')


 let API='http://fitness.h5.itsource.cn:3701' 
 
 //
 userhead.addEventListener('click',()=>{
    location.href='./userDails.html'
 })


  //获取用户信息
  function getUserInfo() {
    request.get('/api/user/info').then(res => {
      // console.log(res.data);
      let {data,errno}=res.data
      console.log(data);
      if(errno===0){
        render(data)

      }
   
    })
  }
  getUserInfo()
  // 渲染函数
  function render( data){
    avater.src=API+data.imgUrl
    days.textContent=data.clockCount
    minsp1.textContent=data.duration
    sumsp1.textContent=data.calorie
    husername.textContent=data.nickName

  }
   //获取打卡信息
   function getClockInfo() {
    request.get('/api/user/clockInInfo')
      .then(res => {
        // console.log(res.data);
      let {data,errno}=res.data
      console.log(data);
      if(errno===0){
        if(data.isClockIn){
            nowday.textContent='今日已打卡'
            nowday.className='nowcarded nowday'
        }else{
            nowday.textContent='今日打卡'
          nowday.className=' nowday'
        }
      }

      })
  }
  getClockInfo()

}
